|
|
|
|
|
|
|
Figure 15.1
A backface is hidden from the center of
projection by the solid's body. |
|
|
|
|
|
|
|
|
of which will not be backfaces. In that case, you do not need to draw this surface because its visible edges will be drawn by other surfaces. |
|
|
|
|
|
|
|
|
To use this information to perform backface removal, you need to do two things. First, you must be able to compute surface normals. Second, you must be able to determine what angle the viewing direction makes with the surface normals. |
|
|
|
|
|
|
|
|
You can easily find a surface normal by taking the vector cross-product between two of the surface's adjacent edges. The cross-product of two vectors with components A = <x1, y1, z1> and B = <x2, y2, z2> is written ''A x B" and is defined as: |
|
|
|
 |
|
|
|
|
<y1 * z2 - y2 * z1, x2 * z1 - x1 * z2, x1 * y2 - x2 * y1> |
|
|
|
|
|
|
|
|
You can use the m3Cross subroutine defined in module M3Ops.bas to compute vector cross-products. This routine takes as parameters the X, Y, and Z components of the vectors A and B. It returns through parameters the components of the vector cross-product. |
|
|
|
 |
|
|
|
|
' Compute the cross product of two vectors.
' Set <X, Y, Z> = <x1, y1, z1> X <x2, y2, z2>. Public Sub m3Cross(ByRef X As Single, ByRef Y As Single, _
ByRef Z As Single, ByVal x1 As Single, _
ByVal y1 As Single, ByVal z1 As Single, _
ByVal x2 As Single, ByVal y2 As Single, _
ByVal z2 As Single)
X = y1 * z2 - z1 * y2
Y = z1 * x2 - x1 * z2
Z = x1 * y2 - y1 * x2
End Sub |
|
|
|
|
|
|
|
|
If |A| and |B| are the lengths of the vectors A and B, respectively, and q is the angle between them, the cross-product vector has length |A| * |B| * Sin(q). |
|
|
|
|
|
|
|
|
The cross-product is a vector that is perpendicular to both vectors A and B, but there are two directions perpendicular to vectors A and B. For example, if A and B lie in a horizontal plane, a perpendicular vector could point upward or downward. The direction of |
|
|
|
|
|